package com.shuqi.model;

import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.shuqi.application.ShuqiApplication;
import com.shuqi.common.MyTask;
import com.shuqi.common.Urls;
import com.shuqi.common.utils.HttpCommonParamsUtils;
import com.shuqi.model.manager.MyAccountManager;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.parser.AccountUserAgeParser;

public class UserAgeModel extends ModelBase implements HttpRequestListener {
    private HttpRequest httpRequest;
    private Context mContext;

    public UserAgeModel(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void action(int actionCode, Object object) {
        fireEvent(actionCode, object);
    }

    @Override
    public List<BasicNameValuePair> setParams() {
        String userId = MyAccountManager.getInstance(ShuqiApplication.getContext()).getUserId();
        return HttpCommonParamsUtils.getShuQiBasicParams(userId);
    }

    @Override
    public String getRequestUrl() {
        return Urls.getUserBookAgeUrl();
    }

    @Override
    public void loadData(Object... objs) {
        httpRequest =
                new HttpRequest(mContext, UrlManager.COLUMN_DOMAIN_READ, getRequestUrl(),
                        setParams(), this);
        httpRequest.setDataParseAdapter(new AccountUserAgeParser());
        MyTask.runInBackground(httpRequest, true);
    }

    @Override
    public void onDestroy() {
        if (httpRequest != null) {
            httpRequest.abort();
        }
    }

}
